{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1. 对象的布尔值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "---------以下对象的布尔值为False-----------\n",
      "False\n",
      "False\n",
      "False\n",
      "False\n",
      "False\n",
      "False\n",
      "False\n",
      "False\n",
      "False\n",
      "False\n",
      "False\n",
      "False\n",
      "False\n",
      "---------除以上，其他对象的布尔值为True-----------\n",
      "True\n",
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "# 测试对象的布尔值\n",
    "# 可以把对象直接放在if条件语句中判断，写下一步语句\n",
    "print('---------以下对象的布尔值为False-----------')\n",
    "print(bool(False))\n",
    "print(bool(0))\n",
    "print(bool(0.0))\n",
    "print(bool(None))\n",
    "print(bool(''))  # 长度为0的字符串对象\n",
    "print(bool(\"\"))  # 长度为0的字符串对象\n",
    "print(bool([]))  # 空列表[]\n",
    "print(bool(list()))  # 空列表\n",
    "print(bool(()))  # 空元组\n",
    "print(bool(tuple()))  # 空元祖\n",
    "print(bool({}))  # 空字典\n",
    "print(bool(dict()))  # 空字典\n",
    "print(bool(set()))  # 空集合\n",
    "\n",
    "print('---------除以上，其他对象的布尔值为True-----------')\n",
    "print(bool(18))\n",
    "print(bool(True))\n",
    "print(bool('helloworld'))  # 不是空字符串"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.6.3",
   "language": "python",
   "name": "python3.6.3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
